package com.lingCheng.avg.service.impl;


import com.lingCheng.avg.common.TaskStatisticsData;
import com.lingCheng.avg.entity.WmsTaskHis;
import com.lingCheng.avg.mapper.WmsTaskHisMapper;
import com.lingCheng.avg.service.WmsTaskHisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
@Slf4j
public class WmsTaskHisServiceImpl implements WmsTaskHisService {
    @Autowired
    private WmsTaskHisMapper wmsTaskHisMapper;

    @Override
    public TaskStatisticsData findTodayAllRW() {
        List<WmsTaskHis> todayAllRW = wmsTaskHisMapper.findTodayAllRW();
        TaskStatisticsData data = new TaskStatisticsData();
        List<String> time = new ArrayList<>();
        List<Map<String,Object>> listMap = new LinkedList<Map<String, Object>>();
        List<Integer> YLin = new ArrayList<>();
        List<Integer> CPout = new ArrayList<>();
        List<Integer> CPin = new ArrayList<>();
        List<Integer> YLout = new ArrayList<>();

        Map<String,Object> YLinMap = new HashMap<>();
        Map<String,Object> CPoutMap = new HashMap<>();
        Map<String,Object> CPinMap = new HashMap<>();
        Map<String,Object> YLoutMap = new HashMap<>();

        YLinMap.put("name","原料入库");
        YLoutMap.put("name","原料出库");
        CPinMap.put("name","成品入库");
        CPoutMap.put("name","成品出库");

        for (WmsTaskHis wmsTaskHis : todayAllRW) {
            // 将时间格式转换为 "7:00" 这种格式
            String formattedTime = wmsTaskHis.getTime() + ":00";
            time.add(formattedTime);
            YLin.add(wmsTaskHis.getYLinCount());
            YLout.add(wmsTaskHis.getYLoutCount());
            CPin.add(wmsTaskHis.getCPinCount());
            CPout.add(wmsTaskHis.getCPoutCount());
        }
        YLinMap.put("value",YLin);
        YLoutMap.put("value",YLout);
        CPinMap.put("value",CPin);
        CPoutMap.put("value",CPout);
        listMap.add(YLinMap);
        listMap.add(YLoutMap);
        listMap.add(CPinMap);
        listMap.add(CPoutMap);

        data.setTime(time.toArray(new String[0]));
        data.setData(listMap);

        return data;
    }

    @Override
    public TaskStatisticsData findSevenDayAllRW() {
        List<WmsTaskHis> sevenDayRW = wmsTaskHisMapper.findSevenDayRW();
        TaskStatisticsData data = new TaskStatisticsData();
        List<Map<String,Object>> listMap = new LinkedList<Map<String, Object>>();
        List<String> time = new ArrayList<>();
        List<Integer> YLin = new ArrayList<>();
        List<Integer> CPout = new ArrayList<>();
        List<Integer> CPin = new ArrayList<>();
        List<Integer> YLout = new ArrayList<>();

        Map<String,Object> YLinMap = new HashMap<>();
        Map<String,Object> CPoutMap = new HashMap<>();
        Map<String,Object> CPinMap = new HashMap<>();
        Map<String,Object> YLoutMap = new HashMap<>();

        YLinMap.put("name","原料入库");
        YLoutMap.put("name","原料出库");
        CPinMap.put("name","成品入库");
        CPoutMap.put("name","成品出库");
        for (WmsTaskHis wmsTaskHis : sevenDayRW) {
            // 将时间格式转换为 "7:00" 这种格式
//            String weekday = wmsTaskHis.getWeekday();
//            if (wmsTaskHis.getWeekday().equals("Monday")){
//                weekday="周一";
//            }else if (wmsTaskHis.getWeekday().equals("Tuesday")){
//                weekday="周二";
//            }else if (wmsTaskHis.getWeekday().equals("Wednesday")){
//                weekday="周三";
//            }else if (wmsTaskHis.getWeekday().equals("Thursday")){
//                weekday="周四";
//            }else if (wmsTaskHis.getWeekday().equals("Friday")){
//                weekday="周五";
//            }else if (wmsTaskHis.getWeekday().equals("Saturday")){
//                weekday="周六";
//            }else if (wmsTaskHis.getWeekday().equals("Sunday")){
//                weekday="周日";
//            }
//            time.add(weekday);
//            in.add(wmsTaskHis.getInCount());
//            out.add(wmsTaskHis.getOutCount());
            time.add(wmsTaskHis.getWeekday());
            YLin.add(wmsTaskHis.getYLinCount());
            YLout.add(wmsTaskHis.getYLoutCount());
            CPin.add(wmsTaskHis.getCPinCount());
            CPout.add(wmsTaskHis.getCPoutCount());
        }
        YLinMap.put("value",YLin);
        YLoutMap.put("value",YLout);
        CPinMap.put("value",CPin);
        CPoutMap.put("value",CPout);
        listMap.add(YLinMap);
        listMap.add(YLoutMap);
        listMap.add(CPinMap);
        listMap.add(CPoutMap);
//        log.info("time:{}",time);
//        log.info("in:{}",in);
//        log.info("out:{}",out);
        data.setTime(time.toArray(new String[0]));
        data.setData(listMap);
        return data;
    }
}
